<?php
namespace Act\Os;

class MailTpl extends Backend{
	public function doAdd(){
		if(is_post()){
			$mod = model('#MailTpl');
			$ret = $mod->addMailTpl($_POST);
			if($ret!=false){
				return $this->success('添加邮件模板成功',referer(referer()));
			}else{
				$this->alert('error',$mod->getError());
			}
		}
		$this->display('form.php');
	}

	public function doUpdate(){
		$tpl_id = get('tpl_id',0,'absint');
		$this->checkParam($tpl_id);
		$mod = model('#MailTpl');
		$tpl = $mod->getMailTplById($tpl_id);
		if(empty($tpl)){
			return $this->error('该模板不存在');
		}
		if (is_post()) {
			$ret = $mod->updateMailTpl($tpl_id,$_POST);
			if($ret!==false){
				return $this->success('修改邮件模板成功',referer(referer()));
			}
			else{
				$this->alert('error',$mod->getError());
			}
			$tpl = $_POST;
		}
		$_POST = $tpl;
		$this->display('form.php');
	}
}